package com.qinggeng.project.system.controller;

import com.qinggeng.common.constant.UserConstants;
import com.qinggeng.common.utils.poi.ExcelUtil;
import com.qinggeng.framework.aspectj.lang.annotation.Log;
import com.qinggeng.framework.aspectj.lang.enums.BusinessType;
import com.qinggeng.framework.web.controller.BaseController;
import com.qinggeng.framework.web.domain.AjaxResult;
import com.qinggeng.framework.web.page.TableDataInfo;
import com.qinggeng.project.system.domain.RiderStatistics;
import com.qinggeng.project.system.service.IRiderStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 骑手数据统计Controller
 *
 * @author qinggeng
 * @date 2020-06-30
 */
@RestController
@RequestMapping("/system/riderStatistics")
public class RiderStatisticsController extends BaseController {
    @Autowired
    private IRiderStatisticsService riderStatisticsService;

    /**
     * 查询骑手数据统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:riderStatistics:list')")
    @GetMapping("/list")
    public TableDataInfo list(RiderStatistics riderStatistics) {
        startPage();
        List<RiderStatistics> list = riderStatisticsService.selectRiderStatisticsList(riderStatistics);
        if (list.size() > 0) {
            for (RiderStatistics riderStatistics1 : list) {
                if (riderStatistics1.getAvatar() == null || riderStatistics1.getAvatar().equals("")) {
                    riderStatistics1.setAvatar(UserConstants.DEFAULT_AVATAR);
                }
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出骑手数据统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:riderStatistics:export')")
    @Log(title = "骑手数据统计", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RiderStatistics riderStatistics) {
        List<RiderStatistics> list = riderStatisticsService.selectRiderStatisticsList(riderStatistics);
        ExcelUtil<RiderStatistics> util = new ExcelUtil<RiderStatistics>(RiderStatistics.class);
        return util.exportExcel(list, "riderStatistics");
    }

    /**
     * 获取骑手数据统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:riderStatistics:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(riderStatisticsService.selectRiderStatisticsById(id));
    }

    /**
     * 新增骑手数据统计
     */
    @PreAuthorize("@ss.hasPermi('system:riderStatistics:add')")
    @Log(title = "骑手数据统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiderStatistics riderStatistics) {
        return toAjax(riderStatisticsService.insertRiderStatistics(riderStatistics));
    }

    /**
     * 修改骑手数据统计
     */
    @PreAuthorize("@ss.hasPermi('system:riderStatistics:edit')")
    @Log(title = "骑手数据统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiderStatistics riderStatistics) {
        return toAjax(riderStatisticsService.updateRiderStatistics(riderStatistics));
    }

    /**
     * 删除骑手数据统计
     */
    @PreAuthorize("@ss.hasPermi('system:riderStatistics:remove')")
    @Log(title = "骑手数据统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(riderStatisticsService.deleteRiderStatisticsByIds(ids));
    }
}
